import 'package:flutter/material.dart';
import 'package:x3_component_core/theme/base_button_theme.dart';

enum CircularType { circular, angle, normal }

class BaseOutLineButton extends StatelessWidget {
  /// 基本颜色
  final Color primaryColor;

  /// 点击
  final Function onPressed;

  /// 是否禁用
  final bool disabled;

  /// 圆弧类型
  final CircularType circularType;

  final double borderWidth;

  /// widget
  final Widget child;

  BaseOutLineButton({
    Key key,
    @required this.onPressed,
    @required this.child,
    this.primaryColor,
    this.disabled = false,
    this.circularType = CircularType.normal,
    this.borderWidth = 0.8,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, constraints) {
      Color _primaryColor = this.primaryColor ?? Theme.of(context).primaryColor;
      double _circular;
      switch (this.circularType) {
        case CircularType.circular:
          _circular = constraints.biggest.height == double.infinity ? 40 : constraints.biggest.height;
          break;
        case CircularType.angle:
          _circular = 0;
          break;
        case CircularType.normal:
          _circular = 2;
          break;
      }
      return Container(
        width: constraints.biggest.width == double.infinity ? null : constraints.biggest.width,
        height: constraints.biggest.height == double.infinity ? 40 : constraints.biggest.height,
        child: OutlineButton(
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(_circular))),
          hoverColor: _primaryColor,
          padding: EdgeInsets.symmetric(horizontal: 16),
          borderSide: BorderSide(
            color: _primaryColor.withOpacity(0.6),
            width: this.borderWidth,
            style: BorderStyle.solid,
          ),
          highlightedBorderColor: _primaryColor,
          textColor: _primaryColor,
          child: DefaultTextStyle(style: Theme.of(context).textTheme.bodyText2.copyWith(fontSize: BaseButtonTheme.buttonTextSize), child: this.child),
          onPressed: this.disabled == true ? null : (this.onPressed ?? () {}),
        ),
      );
    });
  }
}
